package com.springapp.mvc.util;

import com.springapp.mvc.dto.PostResult;
import org.springframework.security.access.AccessDeniedException;

/**
 * Created by dbychkov on 13.01.2015.
 */
public class ExecUtil {

    private static final String ACCESS_DENIED_MESSAGE =
            "You don't have enough permissions to perform this operation";

    public static PostResult exec(PostAction action){
        try {
            action.perform();
            return PostResult.success();
        } catch (AccessDeniedException e) {
            return PostResult.failure(ACCESS_DENIED_MESSAGE);
        } catch (Exception e) {
            return PostResult.failure(e.getMessage());
        }
    }
}
